/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.service.book;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.boxin.ims.modules.wechat.entity.book.BookOrderRecord;
import com.boxin.ims.modules.wechat.dao.book.BookOrderRecordDao;

/**
 * 预定服务记录Service
 * @author Jakemanse
 * @version 2013-12-08
 */
@Component
@Transactional(readOnly = true)
public class BookOrderRecordService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(BookOrderRecordService.class);
	
	@Autowired
	private BookOrderRecordDao bookOrderRecordDao;
	
	public BookOrderRecord get(Long id) {
		return bookOrderRecordDao.findOne(id);
	}
	
	public Page<BookOrderRecord> find(Page<BookOrderRecord> page, BookOrderRecord bookOrderRecord) {
		DetachedCriteria dc = bookOrderRecordDao.createDetachedCriteria();
		if (bookOrderRecord.getUser()!=null && bookOrderRecord.getUser().getId()>0){
			dc.add(Restrictions.eq("user.id", bookOrderRecord.getUser().getId()));
		}
		if (StringUtils.isNotEmpty(bookOrderRecord.getName())){
			dc.add(Restrictions.like("name", "%"+bookOrderRecord.getName()+"%"));
		}
		dc.addOrder(Order.desc("id"));
		return bookOrderRecordDao.find(page, dc);
	}
	
	
	@Transactional(readOnly = false)
	public void save(BookOrderRecord bookOrderRecord) {
		bookOrderRecordDao.save(bookOrderRecord);
	}

	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		bookOrderRecordDao.deleteById(id);
	}
	
}
